<?php
	include_once("../include/init.php");
	include_once("admin_init.php");
	$sql = "SELECT * FROM  tr_order ";
	//查询
	if(isset($_GET['sub'])){
	 		 $sosuo = trim($_GET['sosuo']);

	 		//判断是哪个查询
	 		$sql.= " where ";//组装SQL语句
	 	 if($sosuo != ""){
	 	 	$sql.= " order_sn like '%{$sosuo}%' and";

	 	 }
	 	 	$sql = substr($sql,0,-4);
	 	 	$url = "&order_sn={$sosuo}&sub=搜索";	
  	}
	//分页
	$totalRows= mysql_num_rows(mysql_query($sql));
	$pageRows = 4;
	$totalpage= ceil($totalRows / $pageRows);
	$page = isset($_GET['page'])?$_GET['page']:1;
	if($page <= 0 ||$page >$totalpage ||!is_numeric($page)){
		$page = 1;

	}
	$limitStart =$pageRows *($page -1);
	$sql.= "order by order_id desc limit {$limitStart},{$pageRows}";
	$res = mysql_query($sql);
	$info = [];
	if(mysql_num_rows($res)>0){
		while($list=mysql_fetch_assoc($res)){
			$info[]=$list;
		}
	}
?>


<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>主体部分</title>
	<base target="_self">
	<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
	<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
	<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
		 <form action="order_sosuo.php" method="get">
		  <tr>
		    <td background="./skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' border="0px"><span><img src='./skin/images/frame/arr3.gif' style='margin-right:10px;'>订单列表</span></td>
		   
			<td  background="./skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' border="0px">
				<span>订单编号：</span>
				<input type="text" name="sosuo" value="">
				<input type="submit" name="sub" value="搜索">
			</td>

		  </tr>
		</form>
	  <tr bgcolor="#FFFFFF">
	    <td colspan="2">
			<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CFCFCF" align="center" style="margin-top:8px">
				<tr align="center" bgcolor="#FBFCE2" height="25">
					<td width="6%">订单ID</td>
					<td width="6%">订单编号</td>
					<td width="10%">商品信息</td>
					<td width="10%">总价</td>
					<td width="10%">收件人</td>
					<td width="10%">地址</td>
					<td width="8%">手机号码</td>
					<td width="13%">订单时间</td>
					<td>状态</td>
					<td width="10%">操作</td>
				</tr>
	  <!-- data start-->
	  			<?php foreach ($info as $vo){?>
				<tr align='center' bgcolor="#FFFFFF" height="26" align="center" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
					<td >
						<?=$vo['order_id']?>
					</td>					
					<td nowrap>
						<?=$vo['order_sn']?>
					</td>
					<td >
					<?php
					 	$goods = $vo['order_goods'];
 						$cart = unserialize($goods);
 						foreach($cart as $v){
 							echo $v['pname'].$v['size'];
 						}
					?>
					</td>
					<td>
						￥<?=$vo['order_amount']?>.00
					</td>
					<td>
						<?=$vo['consignee']?>
					</td>
					<td><?=$vo['address']?></td>
					<td><?=$vo['mobile']?></td>
					<td><?=date("Y-m-d H:i:s",$vo['add_time'])?></td>
					<td><?php
							if($vo['order_status']==0){
								echo "未付款";
							}elseif($vo['order_status']==1){
								echo"已付款";
							}elseif($vo['order_status']==3){
								echo"已发货";
							}elseif($vo['order_status']==4){
								echo"已收货";
							}
						?> </td>
					<td>
						<a href="order_edit.php?id=<?=$vo['order_id']?>"><img src='./skin/images/frame/trun.gif' title="编辑" alt="编辑" onClick="QuickEdit(179, event, this);" style='cursor:pointer' border='0' width='16' height='16' /></a>
						<a href="javascript:deleteAdmin(<?=$vo['order_id']?>)">
						<img src='./skin/images/frame/gtk-del.png' title="删除" alt="删除" onClick="editArc(179);" style='cursor:pointer' border='0' width='16' height='16' />
						</a>
					</td>
				</tr>
				<?php }?>
	  <!-- data end-->
	  <!-- select start-->

	  <!-- select end-->
	  <!-- page start-->
		  <tr align="right" bgcolor="#F9FCEF">
			<td height="36" colspan="10" align="center">
				<div class="pagelistbox">
					<span>共<?php echo $totalpage;?>页/<?php echo $totalRows;?>条记录 </span>
					<span class='indexPage'><a href="?page=1">首页 </a>
					<a class='prevPage' href='?page=<?php echo $page-1?>'>上页</a> 
					</span>
					<?php for($i=1;$i<=$totalpage;$i++):?>
						<?php if($i == $page):?>
							<strong><?php echo $i;?></strong>
							<?php else:?>
							<a href='?page=<?php echo $i;?>'><?php echo $i;?></a>
						<?php endif;?>
					<?php endfor;?>
					<a class='nextPage' href='?page=<?php echo $page+1;?>'>下页</a> 
					<a class='endPage' href='?page=<?php echo $totalpage;?>'>末页</a> 
					</div>
				</td>
		  </tr>
	  <!-- page end-->
	</table>
	<script>
		function deleteAdmin(order_id){
			if(confirm('确认删除？')){
				window.location.href = "order.php?act=del&id="+order_id;
			}
		}

	</script>
	</body>
</html>